﻿@model Think9.Models.TbIndexEntity
@{
    ViewBag.Title = "Add";
    Layout = "~/Areas/Shared/_LayuiForm.cshtml";
}

<form class="layui-form" lay-filter="formEdit">
    <input style="display:none" id="tbid" value="@ViewBag.tbid">
    <input style="display:none" id="frm" value="@ViewBag.frm">
    <input style="display:none" id="isSelMuch" value="@Model.isSelMuch">
    <input style="display:none" id="DataType" value="@ViewBag.DataType">
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md6">
            <label class="layui-form-label">指标名称</label>
            <div class="layui-input-block">
                <input type="text" name="IndexName" id="IndexName" placeholder="指标名称" autocomplete="off" class="layui-input" lay-verify="required" readonly="readonly">
            </div>
        </div>
        <div class="layui-col-md6">
            <label class="layui-form-label">指标编码</label>
            <div class="layui-input-block">
                <input type="text" name="IndexId" id="IndexId" placeholder="指标编码" autocomplete="off" class="layui-input" lay-verify="required" readonly="readonly">
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md6">
            <label class="layui-form-label">指标类型</label>
            <div class="layui-input-block">
                <input type="text" name="DataType" id="DataType" placeholder="指标类型" autocomplete="off" class="layui-input" readonly="readonly">
            </div>
        </div>
        <div class="layui-col-md6">

            <label class="layui-form-label">列表排序</label>
            <div class="layui-input-block">
                <input type="text" name="IndexOrderNo" id="IndexOrderNo" placeholder="请输入1-999的整数 录入表内排序号须唯一" autocomplete="off" class="layui-input" lay-verify="required|number" maxlength="3">
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md6">
            <label class="layui-form-label">列表表头</label>
            <div class="layui-input-block">
                <input type="text" name="ListHeadName" id="ListHeadName" placeholder="列表名称(表头)" autocomplete="off" class="layui-input" maxlength="30" lay-verify="required">
            </div>
        </div>
        <div class="layui-col-md6">
            <label class="layui-form-label">列表列宽</label>
            <div class="layui-input-block">
                <input type="text" name="ColumnWith" id="ColumnWith" placeholder="列表列宽 (5至1000之间)" autocomplete="off" class="layui-input" lay-verify="required|number" maxlength="3">
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md12">
            <label class="layui-form-label">默认值</label>
            <div class="layui-input-block">
                <input type="text" name="DefaultV" id="DefaultV" placeholder="默认值 输入或选择" autocomplete="off" class="layui-input">
                <span style="position: absolute;bottom: 10px; right: 5px;">
                    <i class="fa fa-check" style="color:blue" id="selDefaultV"></i>
                    <i class="fa fa-trash-o" style="color:red" id="delDefaultV"></i>
                </span>
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md12">
            <label class="layui-form-label"><i class="layui-icon layui-icon-about" lay-tips="数值型指标才能设置计算式" data-offset="4" id="tipsAuto02"></i>计算式</label>
            <div class="layui-input-block">
                <input type="text" name="Auto02" id="Auto02" placeholder="自动计算式" autocomplete="off" class="layui-input" readonly>
                <span style="position: absolute;bottom: 10px; right: 5px;">
                    <i class="fa fa-edit" style="color:blue" id="selAuto02"></i>
                    <i class="fa fa-trash-o" style="color:red" id="delAuto02"></i>
                </span>
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md6">

        </div>
        <div class="layui-col-md6">

        </div>
    </div>
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md12">
            <label class="layui-form-label"><i class="layui-icon layui-icon-about" lay-tips="数值型、字符型指标才能设置链接属性，设置成功后List页面点击该指标列可打开页面" data-offset="4" id="tipsLinkFlag"></i>链接属性</label>
            <div class="layui-input-block">
                <input type="text" name="LinkStr" id="LinkStr" placeholder="数值型、字符型指标才能设置链接属性，设置成功后List页面点击该指标列可打开页面，包括打开录入表的显示、添加、编辑页面及统计报表页面" autocomplete="off" class="layui-input" readonly>
                <span style="position: absolute;bottom: 10px; right: 5px;">
                    <i class="fa fa-edit" style="color:blue" id="selLink"></i>
                    <i class="fa fa-trash-o" style="color:red" id="delLink"></i>
                </span>
            </div>
        </div>
    </div>

    <fieldset class="table-fieldset">
        <div class="layui-form-item">
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input type="hidden" name="isEmpty" value="1">
                    <input type="checkbox" name="isEmpty" id="isEmpty" lay-skin="primary" title="必填" value="2" lay-filter="isEmpty">
                    <span style="position: absolute;bottom: 0px; left: 60px;">
                        <i class="layui-icon layui-icon-about" lay-tips="勾选后将进行不能为空检测" data-offset="4"></i>
                    </span>
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="isUnique" value="2">
                    <input type="checkbox" name="isUnique" id="isUnique" lay-skin="primary" title="唯一" value="1" lay-filter="isUnique">
                    <span style="position: absolute;bottom: 0px; left: 60px;">
                        <i class="layui-icon layui-icon-about" lay-tips="勾选后将进行唯一检测" data-offset="4"></i>
                    </span>
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="isPK" value="2">
                    <input type="checkbox" name="isPK" id="isPK" lay-skin="primary" title="主键" value="1" lay-filter="isPK">
                    <span style="position: absolute;bottom: 0px; left: 60px;">
                        <i class="layui-icon layui-icon-about" lay-tips="勾选后将设置为主键的多个字段组合在一起进行唯一检测" data-offset="4"></i>
                    </span>
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="isOrder" value="2">
                    <input type="checkbox" name="isOrder" id="isOrder" lay-skin="primary" title="排序" value="1" lay-filter="isOrder">
                    <span style="position: absolute;bottom: 0px; left: 60px;">
                        <i class="layui-icon layui-icon-about" lay-tips="勾选后List页面可以该字段进行排序" data-offset="4"></i>
                    </span>
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="isSearch" value="2">
                    <input type="checkbox" name="isSearch" id="isSearch" lay-skin="primary" title="查询条件" value="1" lay-filter="isSearch" disabled="disabled">
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="isSearch2" value="2">
                    <input type="checkbox" name="isSearch2" id="isSearch2" lay-skin="primary" title="快速查询" value="1" lay-filter="isSearch2">
                    <span style="position: absolute;bottom: 0px; left: 90px;">
                        <i class="layui-icon layui-icon-about" lay-tips="勾选后List页面可以使用该字段进行筛选查询" data-offset="4"></i>
                    </span>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input type="hidden" name="isColumnShow" value="2">
                    <input type="checkbox" name="isColumnShow" id="isColumnShow" lay-skin="primary" title="Excel列表显示" value="1" lay-filter="isColumnShow" disabled="disabled">
                    <span style="position: absolute;bottom: 0px; left: 130px;">
                        <i class="layui-icon layui-icon-about" lay-tips="勾选后导出Excel文件包含此列" data-offset="4"></i>
                    </span>
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="ListStat" value="2">
                    <input type="checkbox" name="ListStat" id="ListStat" lay-skin="primary" title="统计求和(数值类型)" value="1" lay-filter="ListStat">
                    <span style="position: absolute;bottom: 0px; left: 155px;">
                        <i class="layui-icon layui-icon-about" lay-tips="只对数值类型指标有效，勾选后将在末行显示合计值" data-offset="4"></i>
                    </span>
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="isTime" value="2">
                    <input type="checkbox" name="isTime" id="isTime" lay-skin="primary" title="日期+时间(日期类型)" value="1" lay-filter="isTime">
                    <span style="position: absolute;bottom: 0px; left: 165px;">
                        <i class="layui-icon layui-icon-about" lay-tips="只对日期类型指标有效，勾选后将以YYYY-MM-DD HH:MM:SS格式显示时间" data-offset="4"></i>
                    </span>
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="Code01" value="2">
                    <input type="checkbox" name="Code01" id="Code01" lay-skin="primary" title="可扫码" value="1" lay-filter="Code01" disabled="disabled">
                    <span style="position: absolute;bottom: 0px; left: 75px;">
                        <i class="layui-icon layui-icon-about" lay-tips="待升级" data-offset="4"></i>
                    </span>
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="isHtmlTag" value="2">
                    <input type="checkbox" name="isHtmlTag" id="isHtmlTag" lay-skin="primary" title="显示HtmlTag" value="1" lay-filter="isHtmlTag">
                    <span style="position: absolute;bottom: 0px; left: 110px;">
                        <i class="layui-icon layui-icon-about" lay-tips="勾选后Form页面采用@Html.Raw()显示数据，html格式的字符串以常规标签的格式进行渲染输出" data-offset="4"></i>
                    </span>
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="isShow" value="1">
                    <input type="checkbox" name="isShow" id="isShow" lay-skin="primary" title="隐藏指标(Form页面不显示)" value="2" lay-filter="isShow">
                    <span style="position: absolute;bottom: 0px; left: 200px;">
                        <i class="layui-icon layui-icon-about" lay-tips="编辑Form页面不显示隐藏指标，隐藏指标可作为标志字段，通过数据回写、自定义事件等方式修改该指标的值" data-offset="4"></i>
                    </span>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <select lay-verify="required" name="isColumnShow2" id="isColumnShow2">
                        <option value="1">List页面列表显示(PC端、移动端均显示)</option>
                        <option value="2">List页面列表不显示(PC端、移动端均不显示)</option>
                        <option value="9">List页面列表PC端显示移动端不显示</option>
                    </select>
                </div>
                <div class="layui-input-inline" style="width:150px;">
                    <select lay-verify="required" name="isLock" id="isLock">
                        <option value="2">不锁定</option>
                        <option value="1">锁定(不可编辑)</option>
                        <option value="9">编辑时锁定</option>
                    </select>
                </div>
            </div>
        </div>
    </fieldset><br />
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md6">
            <label class="layui-form-label">控件类型</label>
            <div class="layui-input-block">
                @Html.DropDownList("ControlType", (IEnumerable<SelectListItem>)ViewBag.ControlType, "==请选择控件类型==", new Dictionary<string, object> { { "lay-verify", "required" } })
            </div>
        </div>
        <div class="layui-col-md6">
            <label class="layui-form-label">数据规范</label>
            <div class="layui-input-block">
                <input type="text" name="RuleName" id="RuleName" placeholder="数据规范" class="layui-input" readonly="readonly">
                <span style="position: absolute;bottom: 25px; right: 5px;">
                    <i class="fa fa-edit" style="color:blue" id="selRule"></i>
                </span>
                <span style="color: #FE7300; font-size: 12px;">弹出的编辑页面中选择可多选，可设置为可多选的弹出页面</span>
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space10" style="display:none">
        <div class="layui-col-md12">
            <label class="layui-form-label">提示说明</label>
            <div class="layui-input-block">
                <input type="text" name="ControlBy1" id="ControlBy1" placeholder="提示说明" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="edit">编 辑</button>
        </div>
    </div>
</form>
<script>
    layui.use(["form", "exLayer", "exUtils", "layer"], function () {
        let form = layui.form;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        let layer = layui.layer;

        let $ = layui.$;

        getVal();
        form.render(); //

        form.verify({
            name: function (value, item) {
                if (!new RegExp("^[\u4e00-\u9fa5_a-zA-Z0-9]+$").test(value)) {
                    return '由汉字、数字、字母、下划线组成，不得包含其他字符';
                }
            }
        });

        $("#selRule").click(function () {
            exLayer.open("录入表指标数据规范选择", "/SysTable/TbSetUp/SelectRuleList?tbid=" + $("#tbid").val() + "&indexid=" + $('#IndexId').val() + "&ismuch=" + $('#isSelMuch').val(), '100%', '100%', '0px', '0px', null, null);
        });

        $("#selAuto02").click(function () {
            if ($("#DataType").val() == '3') {
                exLayer.open("计算式", "/SysTable/TbSetUp/PUFormula?tbid=" + $("#tbid").val() + "&fid=main" + "&some=" + $('#Auto02').val(), '100%', '100%', '0px', '0px', null, null);
            }
            else {
                layer.msg('数值型指标才能设置计算式');
            }
        });

        $("#selDefaultV").click(function () {
            exLayer.openMiddle('选择系统指标', '/Com/ComSelect/SelectParm2?type=' + $("#DataType").val(), '500px', '450px', layui.device().mobile);
        });

        $("#selLink").click(function () {
            if ($("#DataType").val() == '3' || $("#DataType").val() == '2' || $("#DataType").val() == '1') {
                exLayer.open("链接属性", "/SysTable/TbSetUp/EditIndexLink?tbid=" + $("#tbid").val() + "&indexid=" + $('#IndexId').val(), '100%', '100%', '0px', '0px', null, null);
            }
            else {
                layer.msg('图像类型不能设置链接属性');
            }
        });

        $("#delAuto02").click(function () {
            $('#Auto02').val('');
        });

        $("#delDefaultV").click(function () {
            $('#DefaultV').val('');
        });

        $("#delLink").click(function () {
            exLayer.confirm("确定要删除吗？", function (index) {
                layer.close(index);
                $('#LinkStr').val('');
                exUtils.ajax("/SysTable/TbSetUp/DelLink", "get", {
                    tbid: $("#tbid").val(), indexid: $('#IndexId').val()
                }, true).done(function (response) {

                }).fail(function (error) {
                    console.log(error);
                });
            });
        });

        //赋值
        form.val("formEdit", {
            "IndexId": "@Model.IndexId",
            "IndexName": "@Model.IndexName",
            "DataType": "@Model.DataType",
            "IndexOrderNo": "@Model.IndexOrderNo",
            "ListHeadName": "@Model.ListHeadName",
            "ColumnWith": "@Model.ColumnWith",
            "DefaultV": "@Model.DefaultV",
            "Auto02": "@Model.Auto02",
            "ControlType": "@Model.ControlType",
            "RuleName": "@Model.RuleName",
            "isLock": "@Model.isLock",
            "isColumnShow2": "@Model.isColumnShow2",
            "LinkStr": "@Model.LinkStr",
            "ControlBy1": "@Html.Raw(Model.ControlBy1)"
        });

        form.on("submit(edit)", function (data) {
            exUtils.ajax("/SysTable/TbSetUp/UpTbIndexByTbIndexID?tbid=" + $("#tbid").val() + "&indexid=" + $('#IndexId').val(), "post", data.field, true).done(function (response) {
                exLayer.greenTickMsg(response.message, function () {
                    if ($("#frm").val() == 'list') {
                        parent.location.reload(); // 父页面刷新
                    }
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }).fail(function (error) {
                console.log(error);
            });
            return false;
        });

        function getVal() {
            if ($('#Auto02').val() == "") {
                $('#tipsAuto02').attr("lay-tips", '数值型指标才能设置计算式');//Auto02
            }
            else {
                $('#tipsAuto02').attr("lay-tips", GetTips('@Model.Auto02'));
            }

            if (@Model.isShow == "2") {
                $('#isShow').attr("checked", true);
            }
            else {
                $("#isShow").removeAttr("checked");
            }

            if (@Model.isPK == "1") {
                $('#isPK').attr("checked", true);
            }
            else {
                $("#isPK").removeAttr("checked");
            }

            if (@Model.isUnique == "1") {
                $('#isUnique').attr("checked", true);
            }
            else {
                $("#isUnique").removeAttr("checked");
            }

            if (@Model.isEmpty == "2") {
                $('#isEmpty').attr("checked", true);
            }
            else {
                $("#isEmpty").removeAttr("checked");
            }

            if (@Model.isOrder == "1") {
                $('#isOrder').attr("checked", true);
            }
            else {
                $("#isOrder").removeAttr("checked");
            }

            if (@Model.isSearch == "1") {
                $('#isSearch').attr("checked", true);
            }
            else {
                $("#isSearch").removeAttr("checked");
            }

            if (@Model.isSearch2 == "1") {
                $('#isSearch2').attr("checked", true);
            }
            else {
                $("#isSearch2").removeAttr("checked");
            }

            if (@Model.isColumnShow == "1") {
                $('#isColumnShow').attr("checked", true);
            }
            else {
                $("#isColumnShow").removeAttr("checked");
            }

            if (@Model.Code01 == "1") {
                $('#Code01').attr("checked", true);
            }
            else {
                $("#Code01").removeAttr("checked");
            }

            if (@Model.ListStat == "1") {
                $('#ListStat').attr("checked", true);
            }
            else {
                $("#ListStat").removeAttr("checked");
            }

            if (@Model.isTime == "1") {
                $('#isTime').attr("checked", true);
            }
            else {
                $("#isTime").removeAttr("checked");
            }

            if (@Model.isHtmlTag == "1") {
                $('#isHtmlTag').attr("checked", true);
            }
            else {
                $("#isHtmlTag").removeAttr("checked");
            }
        }

        function GetTips(some) {
            var _return = "";
            $.ajax({
                url: "/SysTable/TbIndex/GetTbIndexTips",
                type: "post",
                data: { str: some },
                dataType: "json",
                async: false,
                success: function (result) {
                    _return = result;
                }
            });
            return _return;
        };

        //消息提示
        $(document).on("mouseenter", "*[lay-tips]", function () {
            var remind = $(this).attr("lay-tips");
            var tips = $(this).data("offset") || 4;
            var color = $(this).data("color") || '#88858e';
            layer.tips(remind, this, {
                time: -1,
                tips: [tips, color],
                area: ['auto', 'auto'],
            });
        }).on("mouseleave", "*[lay-tips]", function () {
            layer.closeAll("tips");
        });

    });
</script>